//package com.quanshi.accountmanager.utils;
//import cn.hutool.core.codec.Base64Decoder;
//import org.apache.commons.codec.binary.Base64;
//
//import javax.crypto.Cipher;
//import javax.crypto.spec.IvParameterSpec;
//import javax.crypto.spec.SecretKeySpec;
//import java.io.UnsupportedEncodingException;
//import java.nio.charset.StandardCharsets;
//


//<dependency>
//            <groupId>cn.hutool</groupId>
//            <artifactId>hutool-all</artifactId>
//            <version>5.5.8</version>
//        </dependency>
//public class AesUtil {
//
//    public static String KEY = "abc12345abc12345abc12345abc12345"; // 自定义
//    public static String IV = "1234567890123456"; // 自定义
//    private static final String MODE = "AES/CBC/PKCS5Padding"; // 选择CBC模型和PKCS5填充方式
//    private static final String TYPE = "AES";
//
//    /*
//     * AES加密函数
//     */
//    public static String encrypt(String data) {
//        try {
//            IvParameterSpec iv = new IvParameterSpec(IV.getBytes(StandardCharsets.UTF_8));
//            SecretKeySpec sKeySpec = new SecretKeySpec(KEY.getBytes(StandardCharsets.UTF_8),TYPE);
//            Cipher cipher = Cipher.getInstance(MODE);
//            cipher.init(Cipher.ENCRYPT_MODE, sKeySpec, iv);
//            byte[] encrypted = cipher.doFinal(data.getBytes(StandardCharsets.UTF_8));
//            return new String(Base64.encodeBase64(encrypted));	// 需要Base64转化函数
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return null;
//    }
//
//    /*
//     * 密码对比
//     */
//    public static boolean comparePasswords(String encryptedPassword, String userInput){
//        String decryptedPassword = decrypt(encryptedPassword);
//        return decryptedPassword.equals(userInput);
//    }
//
//    /*
//     * AES解密函数
//     */
//    public static String decrypt(String Data){
//        byte[] inputBytes = Base64StringToByteArray(Data);
//        byte[] keyBytes = KEY.getBytes(StandardCharsets.UTF_8);
//        try {
//            SecretKeySpec keySpec = new SecretKeySpec(keyBytes, TYPE);
//            Cipher cipher = Cipher.getInstance(MODE);
//            cipher.init(Cipher.DECRYPT_MODE, keySpec,new IvParameterSpec(IV.getBytes(StandardCharsets.UTF_8)));
//            inputBytes = cipher.doFinal(inputBytes);
//        } catch (Exception e) {
//            e.printStackTrace();
//        };
//        return new String(inputBytes, StandardCharsets.UTF_8);
//    }
//
//    /*
//     * Base64工具类转化
//     */
//    public static byte[] Base64StringToByteArray(String s)
//    {
//        byte[] arr = Base64Decoder.decode(s.substring(s.indexOf(",")+1));
//        return arr;
//    }
//
////
////    //使用AES-128-CBC加密模式，key需要为16位,key和iv可以相同！
////    private static String KEY = "abc12345abc12345abc12345abc12345";
////
////    private static String IV = "1234567890123456";
////
////
////    /**
////     * 加密方法
////     * @param data  要加密的数据
////     * @param key 加密key
////     * @param iv 加密iv
////     * @return 加密的结果
////     * @throws Exception
////     */
////    public static String encrypt(String data, String key, String iv) throws Exception {
////        try {
////
////            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");//"算法/模式/补码方式"NoPadding PkcsPadding
////            int blockSize = cipher.getBlockSize();
////
////            byte[] dataBytes = data.getBytes();
////            int plaintextLength = dataBytes.length;
////            if (plaintextLength % blockSize != 0) {
////                plaintextLength = plaintextLength + (blockSize - (plaintextLength % blockSize));
////            }
////
////            byte[] plaintext = new byte[plaintextLength];
////            System.arraycopy(dataBytes, 0, plaintext, 0, dataBytes.length);
////
////            SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES");
////            IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes());
////
////            cipher.init(Cipher.ENCRYPT_MODE, keyspec, ivspec);
////            byte[] encrypted = cipher.doFinal(plaintext);
////
////            return new Base64().encodeToString(encrypted);
////
////        } catch (Exception e) {
////            e.printStackTrace();
////            return null;
////        }
////    }
////
////    /**
////     * 解密方法
////     * @param data 要解密的数据
////     * @param key  解密key
////     * @param iv 解密iv
////     * @return 解密的结果
////     * @throws Exception
////     */
////    public static String desEncrypt(String data, String key, String iv) throws Exception {
////        try {
////            byte[] encrypted1 = new Base64().decode(data);
////
////            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
////            SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES");
////            IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes());
////
////            cipher.init(Cipher.DECRYPT_MODE, keyspec, ivspec);
////
////            byte[] original = cipher.doFinal(encrypted1);
////            String originalString = new String(original);
////            return originalString;
////        } catch (Exception e) {
////            e.printStackTrace();
////            return null;
////        }
////    }
////
////    /**
////     * 使用默认的key和iv加密
////     * @param data
////     * @return
////     * @throws Exception
////     */
////    public static String encrypt(String data,String key) throws Exception {
////        return encrypt(data, key, IV);
////    }
////
////    /**
////     * 使用默认的key和iv解密
////     * @param data
////     * @return
////     * @throws Exception
////     */
////    public static String desEncrypt(String data,String key) throws Exception {
////        return desEncrypt(data, key, IV);
////    }
////
////
////
////    /**
////     * 测试
////     */
////    public static void Main(String args[]) throws Exception {
////
//////        String test1 = "sa";
//////        String test =new String(test1.getBytes(),"UTF-8");
//////        String data = null;
//////        String key =  KEY;
//////        String iv = IV;
//////        // /g2wzfqvMOeazgtsUVbq1kmJawROa6mcRAzwG1/GeJ4=
//////        data = encrypt(test, key, iv);
//////        System.out.println("数据："+test);
//////        System.out.println("加密："+data);
//////        String jiemi =desEncrypt(data, key, iv).trim();
//////        System.out.println("解密："+jiemi);
////
////
////    }
//
//
//
//
//
//
//
//
//
//
//
////    //算法
////    private static final String ALGORITHMSTR = "AES/ECB/PKCS5Padding";
////
////    /**
////     * aes加密
////     * @param content
////     * @return
////     * @throws Exception
////     */
////    public static String encrypt(String content,String key) {
////        try {
////            return aesEncrypt(content, key);
////        } catch (Exception e) {
////            e.printStackTrace();
////            return "";
////        }
////    }
////
////
////    /**
////     * aes解密
////     * @param encrypt   内容
////     * @return
////     * @throws Exception
////     */
////    public static String decrypt(String encrypt,String key) {
////        try {
////            return aesDecrypt(encrypt, key);
////        } catch (Exception e) {
////            e.printStackTrace();
////            return "";
////        }
////    }
////
////
////
////    /**
////     * 将byte[]转为各种进制的字符串
////     * @param bytes byte[]
////     * @param radix 可以转换进制的范围，从Character.MIN_RADIX到Character.MAX_RADIX，超出范围后变为10进制
////     * @return 转换后的字符串
////     */
////    public static String binary(byte[] bytes, int radix){
////        return new BigInteger(1, bytes).toString(radix);// 这里的1代表正数
////    }
////
////    /**
////     * base 64 encode
////     * @param bytes 待编码的byte[]
////     * @return 编码后的base 64 code
////     */
////    public static String base64Encode(byte[] bytes){
////        return Base64.encodeBase64String(bytes);
////    }
////
////    /**
////     * base 64 decode
////     * @param base64Code 待解码的base 64 code
////     * @return 解码后的byte[]
////     * @throws Exception
////     */
////    public static byte[] base64Decode(String base64Code) throws Exception{
////        return StringUtils.isEmpty(base64Code) ? null : new BASE64Decoder().decodeBuffer(base64Code);
////    }
////
////
////    /**
////     * AES加密
////     * @param content 待加密的内容
////     * @param encryptKey 加***
////     * @return 加密后的byte[]
////     * @throws Exception
////     */
////    public static byte[] aesEncryptToBytes(String content, String encryptKey) throws Exception {
////        KeyGenerator kgen = KeyGenerator.getInstance("AES");
////        kgen.init(128);
////        Cipher cipher = Cipher.getInstance(ALGORITHMSTR);
////        cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(encryptKey.getBytes(), "AES"));
////
////        return cipher.doFinal(content.getBytes("utf-8"));
////    }
////
////
////    /**
////     * AES加密为base 64 code
////     * @param content 待加密的内容
////     * @param encryptKey 加***
////     * @return 加密后的base 64 code
////     * @throws Exception
////     */
////    public static String aesEncrypt(String content, String encryptKey) throws Exception {
////        return base64Encode(aesEncryptToBytes(content, encryptKey));
////    }
////
////    /**
////     * AES解密
////     * @param encryptBytes 待解密的byte[]
////     * @param decryptKey 解***
////     * @return 解密后的String
////     * @throws Exception
////     */
////    public static String aesDecryptByBytes(byte[] encryptBytes, String decryptKey) throws Exception {
////        KeyGenerator kgen = KeyGenerator.getInstance("AES");
////        kgen.init(128);
////
////        Cipher cipher = Cipher.getInstance(ALGORITHMSTR);
////        cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(decryptKey.getBytes(), "AES"));
////        byte[] decryptBytes = cipher.doFinal(encryptBytes);
////        return new String(decryptBytes);
////    }
////
////
////    /**
////     * 将base 64 code AES解密
////     * @param encryptStr 待解密的base 64 code
////     * @param decryptKey 解***
////     * @return 解密后的string
////     * @throws Exception
////     */
////    public static String aesDecrypt(String encryptStr, String decryptKey) throws Exception {
////        return StringUtils.isEmpty(encryptStr) ? null : aesDecryptByBytes(base64Decode(encryptStr), decryptKey);
////    }
//
//    /**
//     * 测试
//     */
////    public static void Main(String[] args) throws Exception {
////        String KEY="1234567812345678";
////        String content = "0xsldFE534654sdfsdf";
////        System.out.println("加密前：" + content);
////        System.out.println("加***和解***：" + KEY);
////        String encrypt = encrypt(content, KEY);
////        System.out.println("加密后：" + encrypt);
////        String decrypt = decrypt(encrypt, KEY);
////        System.out.println("解密后：" + decrypt);
////    }
//}
